<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>返回最后的全局同步 ID (GTID)</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.mysqlnd-ms-get-last-gtid" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">mysqlnd_ms_get_last_gtid</h1>
  <p class="verinfo">(PECL mysqlnd_ms &gt;= 1.2.0)</p><p class="refpurpose"><span class="refname">mysqlnd_ms_get_last_gtid</span> &mdash; <span class="dc-title">返回最后的全局同步 ID (GTID)</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.mysqlnd-ms-get-last-gtid-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   
   <span class="methodname"><strong>mysqlnd_ms_get_last_gtid</strong></span>
    ( <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$connection</code></span>
   ) : <span class="type">string</span></div>

  <p class="para rdfs-comment">
   返回最后一次写操作以后的 GTID，他并不能保证一定是那次写操作产生的 GTID，但是得到的
   GTID 一定比这次写操作产生的 GTID 大。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.mysqlnd-ms-get-last-gtid-parameters">
  <h3 class="title">参数</h3>
  <dl>

   
    <dt>
<code class="parameter">connection</code></dt>

    <dd>

     <p class="para">
      由 <a href="ref.pdo_mysql.html" class="link">PDO_MYSQL</a>, <a href="book.mysqli.html" class="link">mysqli</a>&gt;
      或者 <a href="book.mysql.html" class="link">ext/mysql</a> 产生的 MySQL 服务器连接，
      这些链接受  PECL/mysqlnd_ms 连接控制。连接的创建是通过 mysqlnd_ms 配置文件中
      约定的群组名称建立的。
     </p>
    </dd>

   
  </dl>

 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.mysqlnd-ms-get-last-gtid-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功返回 GTID，失败返回 <strong><code>FALSE</code></strong>。
  </p>
  <p class="para">
   函数通过配置文件中 <em>global_transaction_id_injection</em>
   章节定义的 <em>fetch_last_gtid</em> 参数来获取 GTID。
  </p>
  <p class="para">
   在函数调用的时候，GTID 可能已经增加了。
  </p>
 </div>


 <div class="refsect1 unknown-returnvaluet" id="refsect1-function.mysqlnd-ms-get-last-gtid-unknown-returnvaluet">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    函数需要 PHP &gt;= 5.4.0 版本，PECL/mysqlnd_ms &gt;= 1.2.0 版本，在 PHP 5.3 
    版本中 <em>mysqlnd</em> 库不能使用。
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 examples" id="refsect1-function.mysqlnd-ms-get-last-gtid-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-2270">
    <p><strong>Example #1 <span class="function"><strong>mysqlnd_ms_get_last_gtid()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/*&nbsp;Open&nbsp;mysqlnd_ms&nbsp;connection&nbsp;using&nbsp;mysqli,&nbsp;PDO_MySQL&nbsp;or&nbsp;mysql&nbsp;extension&nbsp;*/<br /></span><span style="color: #0000BB">$mysqli&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">mysqli</span><span style="color: #007700">(</span><span style="color: #DD0000">"myapp"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"username"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"password"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"database"</span><span style="color: #007700">);<br />if&nbsp;(!</span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">)<br />&nbsp;&nbsp;</span><span style="color: #FF8000">/*&nbsp;Of&nbsp;course,&nbsp;your&nbsp;error&nbsp;handling&nbsp;is&nbsp;nicer...&nbsp;*/<br />&nbsp;&nbsp;</span><span style="color: #007700">die(</span><span style="color: #0000BB">sprintf</span><span style="color: #007700">(</span><span style="color: #DD0000">"[%d]&nbsp;%s\n"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">mysqli_connect_errno</span><span style="color: #007700">(),&nbsp;</span><span style="color: #0000BB">mysqli_connect_error</span><span style="color: #007700">()));<br /><br /></span><span style="color: #FF8000">/*&nbsp;auto&nbsp;commit&nbsp;mode,&nbsp;transaction&nbsp;on&nbsp;master,&nbsp;GTID&nbsp;must&nbsp;be&nbsp;incremented&nbsp;*/<br /></span><span style="color: #007700">if&nbsp;(!</span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"DROP&nbsp;TABLE&nbsp;IF&nbsp;EXISTS&nbsp;test"</span><span style="color: #007700">))<br />&nbsp;&nbsp;die(</span><span style="color: #0000BB">sprintf</span><span style="color: #007700">(</span><span style="color: #DD0000">"[%d]&nbsp;%s\n"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">errno</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">error</span><span style="color: #007700">));<br /><br /></span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"GTID&nbsp;after&nbsp;transaction&nbsp;%s\n"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">mysqlnd_ms_get_last_gtid</span><span style="color: #007700">(</span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">));<br /><br /></span><span style="color: #FF8000">/*&nbsp;auto&nbsp;commit&nbsp;mode,&nbsp;transaction&nbsp;on&nbsp;master,&nbsp;GTID&nbsp;must&nbsp;be&nbsp;incremented&nbsp;*/<br /></span><span style="color: #007700">if&nbsp;(!</span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"CREATE&nbsp;TABLE&nbsp;test(id&nbsp;INT)"</span><span style="color: #007700">))<br />&nbsp;&nbsp;die(</span><span style="color: #0000BB">sprintf</span><span style="color: #007700">(</span><span style="color: #DD0000">"[%d]&nbsp;%s\n"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">errno</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">error</span><span style="color: #007700">));<br /><br /></span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"GTID&nbsp;after&nbsp;transaction&nbsp;%s\n"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">mysqlnd_ms_get_last_gtid</span><span style="color: #007700">(</span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.mysqlnd-ms-get-last-gtid-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member">
     <a href="mysqlnd_ms.gtid.html" class="link">Global Transaction IDs</a>
    </li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>